package com.bijava.config;

import io.minio.MinioClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author bijava
 * @version 1.0
 * @since 20-9-8
 */
@Component
public class MinIOConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(MinIOConfig.class) ;

    @Resource
    private ParamConfig paramConfig ;

    private static MinioClient minioClient ;

    /**
     * 初始化 MinIO 客户端
     */
    @PostConstruct
    private void init(){
        try {
            minioClient = MinioClient.builder()
                    .endpoint(paramConfig.getEndpoint())
                    .credentials(paramConfig.getAccessKey(), paramConfig.getSecretKey())
                    .build();
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.info("MinIoClient init fail ...");
        }
    }

    public static MinioClient getMinioClient(){
        return minioClient;
    }
}
